

import * as React from "react";
import { Form, Row, Col, Input, Button, Icon, DatePicker, Select, Table, Tag, Pagination, Modal, InputNumber, ConfigProvider, message, Spin } from 'antd';
import { ColumnProps } from 'antd/es/table';
import * as moment from 'moment';
import './index.scss';
import zhCN from 'antd/es/locale/zh_CN';
// 导出
import ExportCsv from "../../common/export";
import { FormComponentProps } from 'antd/lib/form/Form' //获取form表单的interface
import { dynamicsService } from "../../../../../services/services";
import { ListGUID } from '../../config/ListGuid';
import Api from '../../config/api'
import { Link } from "react-router-dom";
// 检索
import { CAMLFilter, CAMLCompare, CamlQuery, SPDataType, CamlParam, CamlOrderBy } from './../../config/CAMLHelper';
import { Item } from "@pnp/sp/items";
import { isHavePermission, isHavePathPermission } from '../../utils/utils'
interface DataType {
  key: React.Key;
  number: string;
  name: string;
  handle: string;
  relative: Array<any>;
}
interface fromdata {
  field: string;
  text: string;
  errorMessage: string;
  required: boolean;
  type: string;
  value: any;
  options: any;
  theType: any;
  header: any;
  conditions: any;
}
const formItemLayout = {
  labelCol: {
    span: 11,
  },
  wrapperCol: {
    offset: 0,
    span: 13,
  },
}
const { Option } = Select;
const { RangePicker } = DatePicker;
const dateFormat = 'YYYY-MM-DD';
const columns: ColumnProps<DataType>[] = [
  {
    title: 'FL申请书序列号',
    dataIndex: 'sinsei_code',
    key: 'sinsei_code',
    align: 'center',
    width: '200px'
  },
  {
    title: '申请日',
    dataIndex: 'apply_date',
    key: 'apply_date',
    align: 'center',
    width: '200px'
  },
  {
    title: '件名',
    dataIndex: 'filename',
    key: 'filename',
    align: 'center',
  },
  // {
  //   title: '制度内容',
  //   dataIndex: 'handle',
  //   key: 'handle',
  //   align: 'center',
  //   render(text, recod: any) {
  //     return (
  //       <div>
  //         <span>保密程度:{recod.secrecy};到期时间:{recod.expire_date}年;对方公司名称:{recod.company_name};</span>
  //       </div>
  //     )
  //   },
  // }, 
  {
    title: '附件',
    dataIndex: 'file',
    key: 'file',
    align: 'center',
    render: relative => (
      <div>
        {relative && relative.map(tag => {
          const dispUrl = ListGUID.DocumentLink;
          const splitName = tag.Name.split('.');
          return (
            <div key={tag}>
              {
                splitName[splitName.length - 1] === 'xlsx' || splitName[splitName.length - 1] === 'xls' || splitName[splitName.length - 1] === 'docx' || splitName[splitName.length - 1] === 'doc' ? <a href={dispUrl + '?sourcedoc=' + tag.UniqueId} target="_blank">{tag.Name}</a> : <a href={tag.ServerRelativeUrl} download={tag.Name} target="_blank">{tag.Name}</a>
              }
            </div>
          );
        })}
      </div>
    ),
  }
]
const data: DataType[] = [
  {
    key: '1',
    number: 'S s 20200202-01',
    name: '合同1',
    handle: '合同相关内容',
    relative: ['xXXXXXXXX软件开发合XX软件开发合XX软件开发合同1', 'xXXXXXXXX软件开发合XX软件开发合XX软件开发合同2']
  },
  {
    key: '2',
    number: 'B s 20200202-01',
    name: '合同2',
    handle: '合同相关内容',
    relative: ['xXXXXXXXX软件开发合XX软件开发合XX软件开发合同1', 'xXXXXXXXX软件开发合XX软件开发合XX软件开发合同2']
  },
  {
    key: '3',
    number: 'M s 20200202-01',
    name: '合同3',
    handle: '合同相关内容',
    relative: ['xXXXXXXXX软件开发合XX软件开发合XX软件开发合同1', 'xXXXXXXXX软件开发合XX软件开发合XX软件开发合同2']
  },
];
const fromData: fromdata[] = [
  {
    field: 'shenqingri',
    text: '申请日',
    errorMessage: '请输入日期',
    required: false,
    type: 'shenqingri',
    value: null,
    options: [],
    theType: 'DateTime',
    header: "shenqingri",
    conditions: "Eq",
  }, {
    field: 'zuizhong',
    text: '最终更新日期',
    errorMessage: '请输入日期',
    required: false,
    type: 'zuizhong',
    value: null,
    options: [],
    theType: 'DateTime',
    header: "zuizhong",
    conditions: "Eq",
  }, {
    field: 'expire_date',
    text: '到期时间',
    errorMessage: '请输入日期',
    required: false,
    type: 'Picker',
    value: null,
    options: [],
    theType: 'DateTime',
    header: "expire_date",
    conditions: "Eq",
  }, {
    field: 'jianming',
    text: '件名',
    errorMessage: '请输入日期',
    required: false,
    type: 'jianming',
    value: null,
    options: [],
    theType: 'DateTime',
    header: "jianming",
    conditions: "Contains",
  }, {
    field: 'bianhao',
    text: '合同编号',
    errorMessage: '请输入日期',
    required: false,
    type: 'bianhao',
    value: null,
    options: [],
    theType: 'DateTime',
    header: "bianhao",
    conditions: "Eq",
  }, {
    field: 'daima',
    text: '公司代码',
    errorMessage: '请输入日期',
    required: false,
    type: 'daima',
    value: null,
    options: [],
    theType: 'DateTime',
    header: "daima",
    conditions: "Eq",
  }, {
    field: 'fuifangname',
    text: '对方公司名称',
    errorMessage: '请输入日期',
    required: false,
    type: 'fuifangname',
    value: null,
    options: [],
    theType: 'DateTime',
    header: "fuifangname",
    conditions: "Contains",
  }, {
    field: 'contract_confirm',
    text: '合同确认',
    errorMessage: '请选择',
    required: false,
    type: 'select',
    value: undefined,
    options: ['是', '否'],
    theType: 'Text',
    header: "contract_confirm",
    conditions: "Eq",
  }, {
    field: 'for_up_affairs',
    text: '法务上传用',
    errorMessage: '请选择',
    required: false,
    type: 'select',
    value: undefined,
    options: ['法务上传用'],
    theType: 'Text',
    header: "for_up_affairs",
    conditions: "Eq",
  }, {
    field: 'sign_contract',
    text: '签订合同',
    errorMessage: '请选择',
    required: false,
    type: 'select',
    value: undefined,
    options: ['是', '否'],
    theType: 'Text',
    header: "sign_contract",
    conditions: "Eq",
  }, {
    field: 'decision_std',
    text: '决裁基准',
    errorMessage: '请输入',
    required: false,
    type: 'char',
    value: undefined,
    options: [],
    theType: 'Text',
    header: "decision_std",
    conditions: "Contains",
  }, {
    field: 'apply_user_nm',
    text: '申请人',
    errorMessage: '请输入',
    required: false,
    type: 'char',
    value: '',
    options: [],
    theType: 'Text',
    header: "apply_user_nm",
    conditions: "Contains",
  },
  // 姓名
  {
    field: 'sosiki_nm',
    text: '所在部门',
    errorMessage: '请输入',
    required: false,
    type: 'char',
    value: '',
    options: [],
    theType: 'Text',
    header: "sosiki_nm",
    conditions: "Contains",
  }, {
    field: 'sinsei_code',
    text: '申请书序列号',
    errorMessage: '请输入',
    required: false,
    type: 'char',
    value: '',
    options: [],
    theType: 'Text',
    header: "sinsei_code",
    conditions: "Eq",
  }, {
    field: 'secrecy',
    text: '保密程度',
    errorMessage: '请选择',
    required: false,
    type: 'select',
    value: undefined,
    options: ['机密', '密', '社外密', '一般'],
    theType: 'Text',
    header: "secrecy",
    conditions: "Eq",
  }, {
    field: 'expect_decide_date',
    text: '希望决裁日',
    errorMessage: '请输入日期',
    required: false,
    type: 'Picker',
    value: null,
    options: [],
    theType: 'DateTime',
    header: "expect_decide_date",
    conditions: "Eq",
  }, {
    field: 'decision_content_1',
    text: '决裁申请内容1',
    errorMessage: '请输入',
    required: false,
    type: 'char',
    value: undefined,
    options: [],
    theType: 'Text',
    header: "decision_content_1",
    conditions: "Contains",
  }, {
    field: 'decision_content_2',
    text: '决裁申请内容2',
    errorMessage: '请输入',
    required: false,
    type: 'char',
    value: undefined,
    options: [],
    theType: 'Text',
    header: "decision_content_2",
    conditions: "Contains",
  }, {
    field: 'decision_content_3',
    text: '决裁申请内容3',
    errorMessage: '请输入',
    required: false,
    type: 'char',
    value: undefined,
    options: [],
    theType: 'Text',
    header: "decision_content_3",
    conditions: "Contains",
  }, {
    field: 'ddq_flag',
    text: '是否有DDQ',
    errorMessage: '请选择',
    required: false,
    type: 'select',
    value: undefined,
    options: ['有(请上传附件)', '否(请选择理由)'],
    theType: 'Text',
    header: "ddq_flag",
    conditions: "Eq",
  }, {
    field: 'reason_without_ddq',
    text: '无DDQ理由',
    errorMessage: '请选择',
    required: false,
    type: 'select',
    value: undefined,
    options: ['非合同交易', '年交易额10万<', '关联公司之间交易', '销售合同（我方为卖方）及其从合同（不含返利、不良品处理、资产专卖）', '质量、GP保函、GSR承诺、保密等不涉及支付的合同', '担保、贷款等银行合同', '订票、订房协议', '特殊决裁（请提供附件）'],
    theType: 'Text',
    header: "reason_without_ddq",
    conditions: "Eq",
  }, {
    field: 'discuss_depart',
    text: '合议部门',
    errorMessage: '请选择',
    required: false,
    type: 'select',
    value: undefined,
    options: ['所有部长合议'],
    theType: 'Text',
    header: "discuss_depart",
    conditions: "Eq",
  }, {
    field: 'mediate_or_single_decision',
    text: '中间决裁/一次决裁',
    errorMessage: '请选择',
    required: false,
    type: 'select',
    value: undefined,
    options: ['副总经理', '管理部长', '副总-总经理', '副总-执行总经理', '副总-执行总经理-总经理', '无锡人事总务采购物流副总'],
    theType: 'Text',
    header: "mediate_or_single_decision",
    conditions: "Eq",
  }, {
    field: 'operation_meeting',
    text: '经营会议审议',
    errorMessage: '请选择',
    required: false,
    type: 'select',
    value: undefined,
    options: ['不要', '要'],
    theType: 'Text',
    header: "operation_meeting",
    conditions: "Eq",
  }, {
    field: 'board_meeting',
    text: '董事会决议',
    errorMessage: '请选择',
    required: false,
    type: 'select',
    value: undefined,
    options: ['不要', '要'],
    theType: 'Text',
    header: "board_meeting",
    conditions: "Eq",
  }, {
    field: 'decision_flag',
    text: '决裁',
    errorMessage: '请选择',
    required: false,
    type: 'select',
    value: undefined,
    options: ['所属部长', '所属副总经理', '所属总经理', 'SEMW总经理', 'SEMS总经理', 'SEMZ总经理', 'SEMC总经理', 'SEMW品保副总', 'SEMW企划副总', 'SEMU总经理', 'SEMD总经理', 'WPL总经理', 'SEMB总经理', 'SEMA总经理', 'SEMH总经理', '副总-执行总经理', '副总-执行总经理-总经理', '无锡人事总务采购物流副总'],
    theType: 'Text',
    header: "decision_flag",
    conditions: "Eq",
  }, {
    field: 'duration_of_contract',
    text: '合同有效期',
    errorMessage: '请选择',
    required: false,
    type: 'select',
    value: undefined,
    options: ['一次性合同', '自动顺延', '到期续签'],
    theType: 'Text',
    header: "duration_of_contract",
    conditions: "Eq",
  }, {
    field: 'advance_notificate_time',
    text: '提前通知时间',
    errorMessage: '请选择',
    required: false,
    type: 'select',
    value: undefined,
    options: ['=', '>', '<'],
    theType: 'Text',
    header: "advance_notificate_time",
    conditions: "Eq",
  }, {
    field: 'circulation_department',
    text: '回览部门',
    errorMessage: '请选择',
    required: false,
    type: 'select',
    value: undefined,
    options: ['所有部长回览'],
    theType: 'Text',
    header: "circulation_department",
    conditions: "Eq",
  }
  //  {
  //   field: 'operation_meeting_date',
  //   text: '经营会议审议时间',
  //   errorMessage: '请输入日期',
  //   required: false,
  //   type: 'Picker',
  //   value: null,
  //   options: [],
  //   theType: 'DateTime',
  //   header: "operation_meeting_date",
  //   conditions: "Eq",
  // }, {
  //   field: 'board_meeting_date',
  //   text: '董事会决议时间',
  //   errorMessage: '请输入日期',
  //   required: false,
  //   type: 'Picker',
  //   value: null,
  //   options: [],
  //   theType: 'DateTime',
  //   header: "board_meeting_date",
  //   conditions: "Eq",
  // }
]
class SearchApplyRegulationsFile extends React.Component<FormComponentProps> {
  constructor(props: any) {
    super(props);
  }
  /**
* 根据后台返回的 data 中 type 类型生成不同的组件
* @param item  json
* @param Component
*/
  switchItem(item) {
    const type = item.type;
    switch (type) {
      case 'Picker':
        return <RangePicker allowClear format={dateFormat} placeholder={['选择开始日期', '选择结束日期']} />;
      case 'int':
        return <InputNumber style={{ width: '100%' }} />;
      case 'char':
        return <Input allowClear style={{ width: '100%' }} placeholder={item.errorMessage} />;
      case 'date':
        return <DatePicker allowClear format={dateFormat} style={{ width: '100%' }} placeholder={item.errorMessage} />;
      case 'select':
        return (
          <Select allowClear style={{ width: '100%' }} placeholder={item.errorMessage}>
            {
              item.options.map((option, index) => {
                return (<Option value={option} key={option}>{option}</Option>)
              })
            }
          </Select>
        )
      case 'multiSelect':
        return (
          <Select allowClear mode='multiple' maxTagCount={1} style={{ width: '100%' }}   >
            {
              item.options.map((option, index) => {
                return (<Option value={option.Title} key={option.Title}>{option.Title}</Option>)
              })
            }
          </Select>
        )
      case 'shenqingri':
        return (
          <Input.Group compact>
            <RangePicker
              allowClear
              placeholder={['选择开始日期', '选择结束日期']}
              style={{ width: '100%' }}
              onChange={(event) => { this.onChangeRangeDate('filingdate', 'filingdate1', event) }}
              format={"YYYY-MM-DD"}
            />
          </Input.Group>
        )
      case 'zuizhong':
        return (
          <Input.Group compact>
            <RangePicker
              allowClear
              onChange={(event) => { this.onChangeRangeDate('update', 'update1', event) }}
              style={{ width: '100%' }}
              format={"YYYY-MM-DD"}
              placeholder={['选择开始日期', '选择结束日期']}
            />
          </Input.Group>
        )
      case 'jianming':
        return (
          <Input.Group compact>
            <Input
              allowClear
              value={this.state.form.Piecename}
              onChange={(event) => { this.change(event, "Piecename") }}
              className="site-input-right"
              style={{
                width: '100%',
              }}
              placeholder="请输入文件名"
            />
          </Input.Group>
        )
      case 'bianhao':
        return (
          <Input.Group compact>
            <Input
              allowClear
              value={this.state.form.ContractNo}
              onChange={(event) => { this.change(event, "ContractNo") }}
              className="site-input-right"
              style={{
                width: '100%',
                textTransform: 'uppercase'
              }}
              placeholder="请输入合同编号"
            />
          </Input.Group>
        )

      case 'daima':
        return (
          <Input.Group compact>
            <Input
              allowClear
              value={this.state.form.Companycode}
              onChange={(event) => { this.change(event, "Companycode") }}
              className="site-input-right"
              style={{
                width: '100%',
              }}
              placeholder="请输入公司代码"
            />
          </Input.Group>
        )
      case 'fuifangname':
        return (
          <Input.Group compact>
            <Input
              allowClear
              value={this.state.form.corporatename}
              onChange={(event) => { this.change(event, "corporatename") }}
              className="site-input-right"
              style={{
                width: '100%',
              }}
              placeholder="请输入公司名称"
            />
          </Input.Group>
        )



      default:
        return <Input />;
    }
  }
  currentPage = 0
  // list = ['测试数据', '测试数据1'];
  state = {
    ExportCsvVisible: false,
    filter: [
      {
        logic: "and",
        where: [
          {
            key: 'ItemBelong',
            filterType: "Eq",
            value: '1'
          }
        ]
      }
    ],
    exportData: {
      filename: '规章制度导出',//文件名称
      parentElName: 'Button_2',//父元素类名
      elClassName: 'custom',//当前点击元素类名
      dowloadText: '导出CSV',
      isLoading: true,
      headers: [{ label: "制度编号", key: "contract_no" },
      { label: "现在的状况", key: "jotai_kbn" },
      { label: "申请日", key: "apply_date" },
      { label: "最终更新日期", key: "update_time" },
      { label: "申请人code", key: "apply_user_code" },
      { label: "申请人姓名", key: "apply_user_nm" },
      { label: "申请人所在部门code", key: "sosiki_code" },
      { label: "申请人所在部门", key: "sosiki_nm" },
      { label: "申请书序列号", key: "sinsei_code" },
      { label: "紧急程度_id", key: "urgency_id" },
      { label: "紧急程度", key: "urgency" },
      { label: "件名", key: "filename" },
      { label: "公司代码", key: "company_code" },
      { label: "保密程度_ID", key: "secrecy_id" },
      { label: "保密程度", key: "secrecy" },
      { label: "希望决裁日", key: "expect_decide_date" },
      { label: "决裁基准", key: "decision_std" },
      { label: "决裁申请内容1", key: "decision_content_1" },
      { label: "决裁申请内容2", key: "decision_content_2" },
      { label: "决裁申请内容3", key: "decision_content_3" },
      { label: "合同确认_ID", key: "contract_confirm_id" },
      { label: "合同确认", key: "contract_confirm" },
      { label: "法务上传用ID", key: "for_up_id" },
      { label: "法务上传用", key: "for_up_affairs" },
      { label: "是否有DDQ_id", key: "ddq_flag_id" },
      { label: "是否有DDQ", key: "ddq_flag" },
      { label: "无DDQ理由_id", key: "reason_without_ddq_id" },
      { label: "无DDQ理由", key: "reason_without_ddq" },
      { label: "合议部门_id", key: "discuss_depart_id" },
      { label: "合议部门", key: "discuss_depart" },
      { label: "中间决裁/一次决裁_id", key: "mediate_or_single_decision_id" },
      { label: "中间决裁/一次决裁", key: "mediate_or_single_decision" },
      { label: "经营会议审议_id", key: "operation_meeting_id" },
      { label: "经营会议审议", key: "operation_meeting" },
      { label: "经营会议审议日期", key: "operation_meeting_date" },
      { label: "董事会议决_id", key: "board_meeting_id" },
      { label: "董事会议决", key: "board_meeting" },
      { label: "董事会议决日期", key: "board_meeting_date" },
      { label: "决裁_id", key: "decision_flag_id" },
      { label: "决裁", key: "decision_flag" },
      { label: "签订合同_id", key: "sign_contract_id" },
      { label: "签订合同", key: "sign_contract" },
      { label: "合同有效期_id", key: "duration_of_contract_id" },
      { label: "合同有效期", key: "duration_of_contract" },
      { label: "提前通知时间", key: "advance_notificate_time" },
      { label: "到期时间", key: "expire_date" },
      { label: "对方公司名称", key: "company_name" },
      { label: "回览部门_id", key: "circulation_department_id" },
      { label: "回览部门", key: "circulation_department" },
      { label: "附件1", key: "attachment_1" },
      { label: "附件2", key: "attachment_2" },
      { label: "附件3", key: "attachment_3" },
      { label: "DDQ附件", key: "ddq_attachment" },
      { label: "特殊决裁附件", key: "special_judge_attachment" },
      { label: "经营会议审议 添附审议内容", key: "operation_meeting_attachment" },
      { label: "董事会议决 添附审议内容", key: "board_meeting_attachment" },
      { label: "合同附件(最终签订版)", key: "final_contract_attachment" },
      { label: "导入状态", key: "imported_flg" },
      { label: "作成时间", key: "create_date" },
      { label: "作成者", key: "create_user" },
      { label: "修改时间", key: "modify_date" },
      { label: "修改者", key: "modify_user" },],
      data: [//数据源

      ]
    },
    pager: {
      current: 1,
      size: 10
    },
    local: zhCN,
    // 记录条件个数
    data: [],
    allData: [],
    // 总数据数
    totalnum: 0,
    //表单数据对象
    retrieveList: [],
    loading: false,
    inSearchOf: false,
    visible: false,
    //表单数据对象
    form: {
      //申请日
      filingdate: null,
      filingdate1: null,
      //最终更新日期
      update: null,
      update1: null,
      //件名
      Piecename: null,
      //公司代码
      Companycode: null,
      //对方公司名称
      corporatename: null,
      //合同编号
      ContractNo: null,
    },
  }
  onChange = (e, key) => {
    this.setState({
      form: {
        ...this.state.form,
        [key]: e
      }
    })
  }

  // 高级检索按钮
  advanced = () => {
    this.setState({
      visible: true,
    });
  }

  //弹框取消
  handleCancel = () => {
    this.setState({
      visible: false,
    });
  };
  // 输入框改变赋值
  change(e, key) {
    this.setState({
      form: {
        ...this.state.form,
        [key]: e.target.value
      }
    })
  }

  isMiddle = (aa, bb, cc) => {
    var dateBegin = new Date(aa); //将-转化为/，使用new Date
    var dateEnd = new Date(bb); //将-转化为/，使用new Date
    var dateNow = new Date(cc); //获取当前时间
    var dateBeginNew = dateBegin.getTime();
    var dateEndNew = dateEnd.getTime();
    var dateNowNew = dateNow.getTime();
    let num = dateBeginNew
    let num1 = dateEndNew
    let num2 = dateNowNew
    if (num2 >= num && num2 <= num1) {
      return true
    } else {
      return false
    }
  }

  // 获取日期
  onChangeRangeDate = (key, key1, dateString) => {
    // 清空选择时间 直接赋空
    if (dateString.length == 0) {
      this.setState({
        form: {
          ...this.state.form,
          [key]: null,
          [key1]: null
        }
      })
      return
    }
    this.setState({
      form: {
        ...this.state.form,
        [key]: dateString[0] ? moment(dateString[0]).format('YYYY-MM-DD') + ' 00:00:00' : '',
        [key1]: dateString[1] ? moment(dateString[1]).format('YYYY-MM-DD') + ' 23:59:59' : ''
      }
    })

  }
  //弹框确定
  handleSubmit = (e) => {
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      if (!err) {
        // 清空选中条件
        // let params: CamlParam[] = [];
        // let params :any = []
        let params: any = [
          {
            logic: "and",
            where: [
              {
                key: 'ItemBelong',
                filterType: "Eq",
                value: '1'
              }
            ]
          }
        ];
        // params.push(new CamlParam("ItemBelong", '1', SPDataType.Number, CAMLCompare.Eq));//查询合同申请书

        for (let i = 0; i < fromData.length; i++) {
          let size = fromData[i].field + ""
          // if (values[`${size}`] != null && values[`${size}`] != undefined && values[`${size}`] != "") {
          //   if (fromData[i].theType != 'DateTime') {
          //     params.push(new CamlParam(fromData[i].header, values[`${size}`], SPDataType[`${fromData[i].theType}`], CAMLCompare[`${fromData[i].conditions}`]));
          //   } else {
          //     params.push(new CamlParam(fromData[i].header, moment(values[`${size}`][0]).format('YYYY-MM-DD') + "T00:00:00Z", SPDataType.DateTime, CAMLCompare.Geq));
          //     params.push(new CamlParam(fromData[i].header, moment(values[`${size}`][1]).format('YYYY-MM-DD') + "T00:00:00Z", SPDataType.DateTime, CAMLCompare.Leq));
          //   }

          // }

          if (size == "shenqingri") {

            // 申请日 开始
            if (this.state.form.filingdate != "" && this.state.form.filingdate != null) {
              // 2022-10-20T00:00:00Z
              let data = this.state.form.filingdate
              let data1 = this.state.form.filingdate1
              // params.push(new CamlParam("apply_date", size, SPDataType.DateTime, CAMLCompare.Geq));//我这里用的大于等于，你根据你实际情况来
              // params.push({
              //   item: 'apply_date',
              //   text: data,
              //   item1: 'apply_date',
              //   text1: data1,
              //   type: "startEnd"
              // })
              params[0].where.push({
                key: 'apply_date',
                filterType: "Ge",
                value: data
              })
              params[0].where.push({
                key: 'apply_date',
                filterType: "Le",
                value: data1
              })
            }

            //结束日期
            // if (this.state.form.filingdate1 != "" && this.state.form.filingdate1 != null) {
            //   let size = this.state.form.filingdate1 + "T00:00:00Z"
            //   params.push(new CamlParam("apply_date", size, SPDataType.DateTime, CAMLCompare.Leq));//我这里用的小于于等于，你根据你实际情况来
            // }


          } else if (size == "zuizhong") {
            // 最终更新日期 开始日期
            if (this.state.form.update != "" && this.state.form.update != null) {
              // 2022-10-20T00:00:00Z
              let data = this.state.form.update
              let data1 = this.state.form.update1
              // params.push(new CamlParam("update_time", size, SPDataType.DateTime, CAMLCompare.Geq));//我这里用的大于等于，你根据你实际情况来
              // params.push({
              //   item: 'update_time',
              //   text: data,
              //   item1: 'update_time',
              //   text1: data1,
              //   type: "startEnd"
              // })
              params[0].where.push({
                key: 'update_time',
                filterType: "Ge",
                value: data
              })
              params[0].where.push({
                key: 'update_time',
                filterType: "Le",
                value: data1
              })
            }
            //结束日期
            // if (this.state.form.update1 != "" && this.state.form.update1 != null) {
            //   let size = this.state.form.update1 + "T00:00:00Z"
            //   params.push(new CamlParam("update_time", size, SPDataType.DateTime, CAMLCompare.Leq));//我这里用的小于于等于，你根据你实际情况来
            // }

          } else if (size == "jianming") {
            // 件名
            if (this.state.form.Piecename != null && this.state.form.Piecename != "") {
              // params.push(new CamlParam("filename", this.state.form.Piecename, SPDataType.Text, CAMLCompare.Contains));
              // params.push({
              //   item: 'filename',
              //   text: this.state.form.Piecename,
              //   type: 'title',
              // })

              params[0].where.push({
                key: 'filename',
                filterType: "Contains",
                value: this.state.form.Piecename
              })

            }

          } else if (size == "bianhao") {
            // 合同编号
            if (this.state.form.ContractNo != null && this.state.form.ContractNo != "") {
              // params.push(new CamlParam("contract_no", this.state.form.ContractNo, SPDataType.Text, CAMLCompare.Contains));
              // params.push({
              //   item: 'contract_no',
              //   text: this.state.form.ContractNo,
              //   type: 'title',
              // })
              params[0].where.push({
                key: 'contract_no',
                filterType: "Contains",
                value: this.state.form.ContractNo
              })
            }

          } else if (size == "daima") {
            // 公司代码
            if (this.state.form.Companycode != null && this.state.form.Companycode != "") {
              // params.push(new CamlParam("company_code", this.state.form.Companycode, SPDataType.Text, CAMLCompare.Contains));
              // params.push({
              //   item: 'company_code',
              //   text: this.state.form.Companycode,
              //   type: 'title',
              // })
              params[0].where.push({
                key: 'company_code',
                filterType: "Contains",
                value: this.state.form.Companycode
              })
            }

          } else if (size == "fuifangname") {

            // 对方公司名称
            if (this.state.form.corporatename != null && this.state.form.corporatename != "") {
              // params.push(new CamlParam("company_name", this.state.form.corporatename, SPDataType.Text, CAMLCompare.Contains));
              // params.push({
              //   item: 'company_name',
              //   text: this.state.form.corporatename,
              //   type: 'title',
              // })
              params[0].where.push({
                key: 'company_name',
                filterType: "Contains",
                value: this.state.form.corporatename
              })
            }

          } else {

            if (values[`${size}`] != null && values[`${size}`] != undefined && values[`${size}`] != "") {
              if (fromData[i].theType != 'DateTime') {
                // params.push(new CamlParam(fromData[i].header, values[`${size}`], SPDataType[`${fromData[i].theType}`], CAMLCompare[`${fromData[i].conditions}`]));

                // params.push({
                //   item: fromData[i].header,
                //   text: values[`${size}`],
                //   type: 'title',
                // })
                params[0].where.push({
                  key: fromData[i].header,
                  filterType: "Contains",
                  value: values[`${size}`]
                })
              } else {
                // params.push(new CamlParam(fromData[i].header, moment(values[`${size}`][0]).format('YYYY-MM-DD') + "T00:00:00Z", SPDataType.DateTime, CAMLCompare.Geq));
                // params.push(new CamlParam(fromData[i].header, moment(values[`${size}`][1]).format('YYYY-MM-DD') + "T00:00:00Z", SPDataType.DateTime, CAMLCompare.Leq));
                // params.push({
                //   item: fromData[i].header,
                //   text: moment(values[`${size}`][0]).format('YYYY-MM-DD'),
                //   item1: fromData[i].header,
                //   text1: moment(values[`${size}`][1]).format('YYYY-MM-DD'),
                //   type: "startEnd"
                // })
                params[0].where.push({
                  key: fromData[i].header,
                  filterType: "Ge",
                  value: values[`${size}`][0] ? moment(values[`${size}`][0]).format('YYYY-MM-DD') + ' 00:00:00' : '',
                })
                params[0].where.push({
                  key: fromData[i].header,
                  filterType: "Le",
                  value: values[`${size}`][1] ? moment(values[`${size}`][1]).format('YYYY-MM-DD')  + ' 23:59:59' : '',
                })
              }

            }

          }
        }
        // 检索
        this.theQuery(params)

        // 关闭弹窗
        this.setState({
          visible: false,
          confirmLoading: false,
        });
      }
    });
  }
  // 检索合同按钮
  retrieve = (text) => {

    if (this.state.inSearchOf) {
      message.warning('检索中');
      return
    }

    this.setState({
      loading: true,
      inSearchOf: true,
    })
    // 清空选中条件
    // let params: CamlParam[] = [];
    // let params: any = [];
    let params: any = [
      {
        logic: "and",
        where: [
          {
            key: 'ItemBelong',
            filterType: "Eq",
            value: '1'
          }

        ]
      }
    ];
    // params.push(new CamlParam("ItemBelong", '1', SPDataType.Number, CAMLCompare.Eq));//查询合同申请书

    // 因为进入页面就筛选过数据 就不再需要 重新指定申请书进行检索
    // params.push({ item: 'ItemBelong', text: 1 })

    //以下是我写的
    // 申请日 开始
    if (this.state.form.filingdate != "" && this.state.form.filingdate != null) {
      // 2022-10-20T00:00:00Z
      let data = this.state.form.filingdate
      let data1 = this.state.form.filingdate1
      // params.push(new CamlParam("apply_date", size, SPDataType.DateTime, CAMLCompare.Geq));//我这里用的大于等于，你根据你实际情况来
      // params.push({
      //   item: 'apply_date',
      //   text: data,
      //   item1: 'apply_date',
      //   text1: data1,
      //   type: "startEnd"
      // })
      params[0].where.push({
        key: 'apply_date',
        filterType: "Ge",
        value: data
      })
      params[0].where.push({
        key: 'apply_date',
        filterType: "Le",
        value: data1
      })
    }

    //结束日期
    // if (this.state.form.filingdate1 != "" && this.state.form.filingdate1 != null) {
    //   let size = this.state.form.filingdate1 + "T00:00:00Z"
    //   params.push(new CamlParam("apply_date", size, SPDataType.DateTime, CAMLCompare.Leq));//我这里用的小于于等于，你根据你实际情况来
    // }
    //以下是我写的
    // 最终更新日期 开始日期
    if (this.state.form.update != "" && this.state.form.update != null) {
      // 2022-10-20T00:00:00Z
      let data = this.state.form.update
      let data1 = this.state.form.update1
      // params.push(new CamlParam("update_time", size, SPDataType.DateTime, CAMLCompare.Geq));//我这里用的大于等于，你根据你实际情况来
      // params.push({
      //   item: 'update_time',
      //   text: data,
      //   item1: 'update_time',
      //   text1: data1,
      //   type: "startEnd"
      // })
      params[0].where.push({
        key: 'update_time',
        filterType: "Ge",
        value: data
      })
      params[0].where.push({
        key: 'update_time',
        filterType: "Le",
        value: data1
      })
    }

    //结束日期
    // if (this.state.form.update1 != "" && this.state.form.update1 != null) {
    //   let size = this.state.form.update1 + "T00:00:00Z"
    //   params.push(new CamlParam("update_time", size, SPDataType.DateTime, CAMLCompare.Leq));//我这里用的小于于等于，你根据你实际情况来
    // }
    // 件名
    if (this.state.form.Piecename != null && this.state.form.Piecename != "") {
      // params.push(new CamlParam("filename", this.state.form.Piecename, SPDataType.Text, CAMLCompare.Contains));
      // params.push({
      //   item: 'filename',
      //   text: this.state.form.Piecename,
      //   type: 'title',
      // })
      params[0].where.push({
        key: 'filename',
        filterType: "Contains",
        value: this.state.form.Piecename
      })
    }
    // 公司代码
    if (this.state.form.Companycode != null && this.state.form.Companycode != "") {
      // params.push(new CamlParam("company_code", this.state.form.Companycode, SPDataType.Text, CAMLCompare.Contains));
      // params.push({
      //   item: 'company_code',
      //   text: this.state.form.Companycode,
      //   type: 'title'
      // })

      params[0].where.push({
        key: 'company_code',
        filterType: "Contains",
        value: this.state.form.Companycode
      })
    }
    // 对方公司名称
    if (this.state.form.corporatename != null && this.state.form.corporatename != "") {
      // params.push(new CamlParam("company_name", this.state.form.corporatename, SPDataType.Text, CAMLCompare.Contains));
      // params.push({
      //   item: 'company_name',
      //   text: this.state.form.corporatename,
      //   type: 'title'
      // })

      params[0].where.push({
        key: 'company_name',
        filterType: "Contains",
        value: this.state.form.corporatename
      })
    }
    // 合同编号
    if (this.state.form.ContractNo != null && this.state.form.ContractNo != "") {
      // params.push(new CamlParam("contract_no", this.state.form.ContractNo, SPDataType.Text, CAMLCompare.Contains));
      // params.push({
      //   item: 'contract_no',
      //   text: this.state.form.ContractNo,
      //   type: 'title'
      // })
      let pattern = /^[A-Za-z]{1}(?![0-9]+$)(?![A-Za-z]+$)[0-9A-Za-z]*(-)?[0-9]*$/;
      if(pattern.test(this.state.form.ContractNo)) {
        params[0].where.push({
          key: 'contract_no',
          filterType: "Contains",
          value: this.state.form.ContractNo
        })
      } else {
        message.warning('编号格式有误');
        return
      }
      
    }

    this.theQuery(params)
  }
  async exportCsv() {
    let Naturcontract = await Api._getPaged({ Guid: ListGUID.Petition, PageSize: 100000, PageIndex: 1, FilterL: this.state.filter });
    Naturcontract.data.forEach(element => {
      element.decision_content_1 = element.decision_content_1 == null ? "" : element.decision_content_1.replace(RegExp(`"`, "g"), `“`)
      element.decision_content_2 = element.decision_content_2 == null ? "" : element.decision_content_2.replace(RegExp(`"`, "g"), `“`)
      element.decision_content_3 = element.decision_content_3 == null ? "" : element.decision_content_3.replace(RegExp(`"`, "g"), `“`)
      element.apply_date = element.apply_date ? moment(element.apply_date).format('YYYY-MM-DD') : ''
      element.expect_decide_date = element.apply_date ? moment(element.expect_decide_date).format('YYYY-MM-DD') : ''
      element.update_time = element.apply_date ? moment(element.update_time).format('YYYY-MM-DD') : ''
      element.operation_meeting_date = element.apply_date ? moment(element.operation_meeting_date).format('YYYY-MM-DD') : ''
      element.board_meeting_date = element.apply_date ? moment(element.board_meeting_date).format('YYYY-MM-DD') : ''
      element.expire_date = element.apply_date ? moment(element.expire_date).format('YYYY-MM-DD') : ''
      element.create_date = element.apply_date ? moment(element.create_date).format('YYYY-MM-DD') : ''
      element.modify_date = element.apply_date ? moment(element.modify_date).format('YYYY-MM-DD') : ''
    })
    this.setState({
      exportData: {
        ...this.state.exportData,
        data: Naturcontract.data,
        isLoading: false
      }
    })
  }
  async getData() {
    this.setState({
      loading: true
    })
    // this.exportCsv()
    let Naturcontract = await Api._getPaged({ Guid: ListGUID.Petition, PageSize: this.state.pager.size, PageIndex: this.state.pager.current, FilterL: this.state.filter });
    // 追加附件的数据数量
    if(Naturcontract.data) {
      for (let i = 0; i < Naturcontract.data.length; i++) {
        if (Naturcontract.data[i].SRUrls != null) {
          let index = Naturcontract.data[i].SRUrls.indexOf("/")
          Naturcontract.data[i].SRUrls = Naturcontract.data[i].SRUrls.substring(index);
          let file = await Api.getFiles(ListGUID.RegulationsPetitionLibRelativeUrl + '/' + Naturcontract.data[i].SRUrls + '/');
          // 处理时间排序
          // file.sort(function (a, b) {
          //   return b.TimeCreated < a.TimeCreated ? -1 : 1
          // })
  
          
  
          Naturcontract.data[i].file = file
        } else {
          let file = []
          Naturcontract.data[i].file = file
        }
        Naturcontract.data[i].decision_content_1 = Naturcontract.data[i].decision_content_1 == null ? "" : Naturcontract.data[i].decision_content_1.replace(RegExp(`"`, "g"), `“`)
        Naturcontract.data[i].decision_content_2 = Naturcontract.data[i].decision_content_2 == null ? "" : Naturcontract.data[i].decision_content_2.replace(RegExp(`"`, "g"), `“`)
        Naturcontract.data[i].decision_content_3 = Naturcontract.data[i].decision_content_3 == null ? "" : Naturcontract.data[i].decision_content_3.replace(RegExp(`"`, "g"), `“`)
        Naturcontract.data[i].apply_date = Naturcontract.data[i].apply_date ? moment(Naturcontract.data[i].apply_date).format('YYYY-MM-DD') : '';
        Naturcontract.data[i].expect_decide_date = Naturcontract.data[i].apply_date ? moment(Naturcontract.data[i].expect_decide_date).format('YYYY-MM-DD') : '';
        Naturcontract.data[i].update_time = Naturcontract.data[i].update_time ? moment(Naturcontract.data[i].update_time).format('YYYY-MM-DD') : '';
        Naturcontract.data[i].operation_meeting_date = Naturcontract.data[i].operation_meeting_date ? moment(Naturcontract.data[i].operation_meeting_date).format('YYYY-MM-DD') : '';
        Naturcontract.data[i].board_meeting_date = Naturcontract.data[i].board_meeting_date ? moment(Naturcontract.data[i].board_meeting_date).format('YYYY-MM-DD') : '';
        Naturcontract.data[i].expire_date = Naturcontract.data[i].expire_date ? moment(Naturcontract.data[i].expire_date).format('YYYY-MM-DD') : '';
        Naturcontract.data[i].create_date = Naturcontract.data[i].create_date ? moment(Naturcontract.data[i].create_date).format('YYYY-MM-DD') : '';
        Naturcontract.data[i].modify_date = Naturcontract.data[i].modify_date ? moment(Naturcontract.data[i].modify_date).format('YYYY-MM-DD') : '';
      }
      this.setState({
        data: Naturcontract.data,
        // 临时存放所有数据
        // allData: Naturcontract,
        totalnum: Naturcontract.Total,
        loading: false,
        inSearchOf: false,
      })
    } else {
      this.setState({
        loading: false,
        inSearchOf: false,
      })
    }
    

  }
  //动态更新绑定数据
  public async componentDidMount() {
    isHavePathPermission()
    this.getData();// 测试代码，调试API使用

  }


  public render(): React.ReactElement {
    const { visible } = this.state;
    const { getFieldDecorator } = this.props.form;
    return (
      <div className='box'>
        <Spin  spinning={this.state.loading}>
        <div className="box_content">
          <div className="box_top">
            <Row type="flex" justify="end">
              <Col>
                {
                  <Button type="primary" className="Button_1" onClick={this.advanced} >高级检索</Button>
                }
              </Col>
              <Col>
                {
                  <Button type="primary" onClick={this.retrieve}>检索</Button>
                }
              </Col>
              {/* 导出按钮 */}
              {
                  isHavePermission('SearchApplyRegulationsFile/exportcsv') ? <Col><div className="Button_2_1" style={{color: '#fff',cursor: 'pointer'}} onClick={() => this.setState({ExportCsvVisible: true},() => this.exportCsv())}>导出CSV


                  </div></Col> : null
                }
            </Row>
            <div style={{ height: 16, width: 100 }}></div>
            <Row type="flex" justify="space-between">
              <Col span={7}>
                <Form.Item label="申请日" labelCol={{ span: 6 }} wrapperCol={{ span: 18 }} labelAlign="left">
                  <RangePicker
                    allowClear
                    placeholder={['选择开始日期', '选择结束日期']}
                    style={{ width: '100%' }}
                    onChange={(event) => { this.onChangeRangeDate('filingdate', 'filingdate1', event) }}
                    format={"YYYY-MM-DD"}
                  />
                </Form.Item>

              </Col>
              <Col span={7}>

                <Form.Item label="最终更新日期" labelCol={{ span: 6 }} wrapperCol={{ span: 18 }} labelAlign="left">
                  <RangePicker
                    allowClear
                    onChange={(event) => { this.onChangeRangeDate('update', 'update1', event) }}
                    style={{ width: '100%' }}
                    format={"YYYY-MM-DD"}
                    placeholder={['选择开始日期', '选择结束日期']}
                  />
                </Form.Item>

              </Col>
              <Col span={7}>

                <Form.Item label="件名" labelCol={{ span: 6 }} wrapperCol={{ span: 18 }} labelAlign="left">
                  <Input
                    allowClear
                    value={this.state.form.Piecename}
                    onChange={(event) => { this.change(event, "Piecename") }}
                    className="site-input-right"
                    style={{
                      width: '100%',
                    }}
                    placeholder="请输入文件名"
                  />
                </Form.Item>

              </Col>
              <Col span={7}>
                <Form.Item label="公司代码" labelCol={{ span: 6 }} wrapperCol={{ span: 18 }} labelAlign="left">
                  <Input
                    allowClear
                    value={this.state.form.Companycode}
                    onChange={(event) => { this.change(event, "Companycode") }}
                    className="site-input-right"
                    style={{
                      width: '100%',
                    }}
                    placeholder="请输入公司代码"
                  />
                </Form.Item>
              </Col>
              <Col span={7}>
                <Form.Item label="对方公司名称" labelCol={{ span: 6 }} wrapperCol={{ span: 18 }} labelAlign="left">
                  <Input
                    allowClear
                    value={this.state.form.corporatename}
                    onChange={(event) => { this.change(event, "corporatename") }}
                    className="site-input-right"
                    style={{
                      width: '100%',
                    }}
                    placeholder="请输入公司名称"
                  />
                </Form.Item>
              </Col>
              <Col span={7}>
                <Form.Item label="制度编号" labelCol={{ span: 6 }} wrapperCol={{ span: 18 }} labelAlign="left">
                  <Input
                    allowClear
                    value={this.state.form.ContractNo}
                    onChange={(event) => { this.change(event, "ContractNo") }}
                    className="site-input-right"
                    style={{
                      width: '100%',
                      textTransform: 'uppercase'
                    }}
                    placeholder="请输入制度编号"
                  />
                </Form.Item>
              </Col>
            </Row>
          </div>
          <div style={{ height: '24px' }}></div>
          <div className="box_toble">
            <ConfigProvider locale={this.state.local}>
              <Table columns={columns} dataSource={this.state.data}
                pagination={{
                  // onChange: this.ontab.bind(this),
                  onChange: (page, pageSize?) => {
                    this.setState({
                      pager: {
                        current: page,
                        size: pageSize
                      }
                    }, () => {
                      this.getData()
                    })

                  },
                  onShowSizeChange: (page, pageSize?) => {
                    this.setState({
                      pager: {
                        current: page,
                        size: pageSize
                      }
                    }, () => this.getData())
                  },
                  current: this.state.pager.current,
                  pageSize: this.state.pager.size,
                  hideOnSinglePage: false,
                  total: this.state.totalnum,
                  showSizeChanger: true,
                  showQuickJumper: true,
                  defaultCurrent: 1,
                  showTotal: function (total) {
                    return `总共有 ${total} 条数据`;
                  }
                }} />
            </ConfigProvider>
          </div>
          <Modal
            title="导出CSV"
            visible={this.state.ExportCsvVisible}
            onCancel={() => this.setState({ExportCsvVisible: false}, () => dynamicsService.setAbort())}
            maskClosable={false}
            footer={null}
            centered
            destroyOnClose={true}
          >
            {
              this.state.exportData.isLoading ? <div className="spin-text">正在准备数据 <span className="dot-ani"></span></div> : <div className="export_btn" style={{display: 'flex'}}>一共有<span>{this.state.exportData.data.length}</span>条数据，<ExportCsv className="custom" exportData={this.state.exportData} ></ExportCsv></div>
            }
          </Modal>
          <Modal
            destroyOnClose={true}
            visible={visible}
            onCancel={this.handleCancel}
            closable={false}
            footer={null}
            width={'50%'}
          >
            <Form onSubmit={this.handleSubmit} layout='inline' >
              <Row>
                {
                  fromData.map((item, index) => {
                    // type 为 date 日期格式需要强制转化为 moment 格式
                    item.value = item.type == 'date' ? item.value == null ? null : moment(item.value, 'YYYY-MM-DD') : item.value;
                    // item.value = item.type == 'date' ? moment(item.value, 'YYYY-MM-DD') : item.value;
                    return (
                      <Col span={11} offset={index % 2 == 0 ? 0 : 2}>
                        <Form.Item
                          key={index}
                          {...formItemLayout}
                          label={item.text}
                          style={{ display: 'flex', marginTop: '15px' }}
                        >
                          {getFieldDecorator(item.field, {
                            initialValue: item.value,
                            rules: [{
                              required: item.required,
                              message: item.errorMessage
                            }],
                          })(
                            this.switchItem(item)
                          )}
                        </Form.Item>
                      </Col>

                    )
                  })
                }
              </Row>
              <div style={{ height: '24px' }}></div>
              <Row>
                <Col span={3} offset={9}>
                  <Form.Item>
                    <Button type="primary" style={{ padding: ' 0 24px' }} onClick={this.handleSubmit}>检索</Button>
                  </Form.Item>
                </Col>
                <Col span={3}>
                  <Form.Item>
                    <Button type="default" style={{ padding: ' 0 24px' }} onClick={this.handleCancel}>取消</Button>
                  </Form.Item>
                </Col>
              </Row>
            </Form>
          </Modal>
        </div>
        </Spin>
        
      </div>

    );
  }
  public async getTest() {


  }
  public async theQuery(params) {
    this.setState({
      filter: params,
      pager: {
        current: 1,
        size: 10
      }
    }, () => {
      this.getData()
    })
    // 检索结果的list
    // let screenList = []
    // if (params.length == 0) {
    //   
    //   // allData
    //   this.setState({
    //     loading: false,
    //     inSearchOf: false,
    //     data: this.state.allData,
    //     totalnum: this.state.allData.length,
    //   })
    // } else {
    //   
    //   // startEnd  开始结束时间
    //   // test  文本
    //   
    //   this.setState({
    //     filter: params
    //   })
    //   for (let index = 0; index < this.state.allData.length; index++) {
    //     let ifs = ""
    //     for (let j = 0; j < params.length; j++) {
    //       let size = params[j].item + ""
    //       // 
    //       // 
    //       if (params.length == j + 1) {
    //         if (params[j].type == "title") {
    //           ifs += `${params[j].text.includes(this.state.allData[index][`${size}`])}`
    //         } else if (params[j].type == "test") {
    //           ifs += `${"'" + params[j].text.includes(this.state.allData[index][`${size}`]) + "'"}`
    //         } else if (params[j].type == "startEnd") {
    //           let dataSize = this.isMiddle(params[j].text, params[j].text1, this.state.allData[index][`${size}`])
    //           ifs += `${dataSize}`
    //         }
    //         // ifs += `${"'" + params[j].text.includes(this.state.allData[index][`${size}`]) + "'"}`
    //       } else {
    //         // ifs += `${"'" + params[j].text + "'"} == ${"'" + this.state.allData[index][`${size}`] + "'"} ||`
    //         if (params[j].type == "title") {
    //           ifs += `${params[j].text.includes(this.state.allData[index][`${size}`])} &&`
    //         } else if (params[j].type == "test") {
    //           ifs += `${"'" + params[j].text.includes(this.state.allData[index][`${size}`]) + "'"} &&`
    //         } else if (params[j].type == "startEnd") {
    //           let dataSize = this.isMiddle(params[j].text, params[j].text1, this.state.allData[index][`${size}`])
    //           ifs += `${dataSize}  &&`

    //         }
    //       }
    //     }
    //     // 
    //     if (
    //       eval(ifs)
    //     ) {
    //       screenList.push(this.state.allData[index])
    //       // 固定資産廃棄処分申請（二）
    //     }

    //   }

    //   let size = 0
    //   // 追加附件的数据数量

    //   let num = 10
    //   if (screenList.length == 0) {
    //     setTimeout(() => {
    //       this.setState({
    //         exportData:{
    //           ...this.state.exportData,
    //           data: screenList
    //         }
    //       })
    //       this.setState({
    //         loading: false,
    //         inSearchOf: false,
    //         data: screenList,
    //         totalnum: screenList.length,
    //       })
    //       
    //       return
    //     }, 500)
    //   }

    //   if (screenList.length < 10) {
    //     num = screenList.length
    //   }

    //   let arr = []
    //   for (let i = 0; i < num; i++) {
    //     arr.push(screenList[size])
    //     size++
    //   }

    //   arr.forEach(async element => {
    //     if (element.SRUrls != null) {
    //       let index = element.SRUrls.lastIndexOf("/")
    //       element.SRUrls = element.SRUrls.substring(0, index);
    //       let file = await Api.getFiles(element.SRUrls);
    //       element.file = file
    //     } else {
    //       let file = []
    //       element.file = file
    //     }
    //     // return
    //   });

    //   screenList.forEach(element => {
    //     element.decision_content_1 = element.decision_content_1 == null ? "" : element.decision_content_1.replace(RegExp(`"`, "g"), `“`)
    //     element.decision_content_2 = element.decision_content_2 == null ? "" : element.decision_content_2.replace(RegExp(`"`, "g"), `“`)
    //     element.decision_content_3 = element.decision_content_3 == null ? "" : element.decision_content_3.replace(RegExp(`"`, "g"), `“`)
    //     element.apply_date = element.apply_date ? moment(element.apply_date).format('YYYY-MM-DD') : ''
    //     element.expect_decide_date = element.apply_date ? moment(element.expect_decide_date).format('YYYY-MM-DD') : ''
    //     element.update_time = element.apply_date ? moment(element.update_time).format('YYYY-MM-DD') : ''
    //     element.operation_meeting_date = element.apply_date ? moment(element.operation_meeting_date).format('YYYY-MM-DD') : ''
    //     element.board_meeting_date = element.apply_date ? moment(element.board_meeting_date).format('YYYY-MM-DD') : ''
    //     element.expire_date = element.apply_date ? moment(element.expire_date).format('YYYY-MM-DD') : ''
    //     element.create_date = element.apply_date ? moment(element.create_date).format('YYYY-MM-DD') : ''
    //     element.modify_date = element.apply_date ? moment(element.modify_date).format('YYYY-MM-DD') : ''
    //     // if (element.apply_date != null) {
    //     //   element.apply_date = new Date(element.apply_date).getFullYear() + '-' + (new Date(element.apply_date).getMonth() + 1) + '-' + new Date(element.apply_date).getDate()
    //     // } else {
    //     //   element.apply_date = ""
    //     // }
    //     // if (element.expect_decide_date != null) {
    //     //   element.expect_decide_date = new Date(element.expect_decide_date).getFullYear() + '-' + (new Date(element.expect_decide_date).getMonth() + 1) + '-' + new Date(element.expect_decide_date).getDate()
    //     // } else {
    //     //   element.expect_decide_date = ""
    //     // }

    //     // if (element.update_time != null) {
    //     //   element.update_time = new Date(element.update_time).getFullYear() + '-' + (new Date(element.update_time).getMonth() + 1) + '-' + new Date(element.update_time).getDate()
    //     // } else {
    //     //   element.update_time = ""
    //     // }
    //     // if (element.operation_meeting_date != null) {
    //     //   element.operation_meeting_date = new Date(element.operation_meeting_date).getFullYear() + '-' + (new Date(element.operation_meeting_date).getMonth() + 1) + '-' + new Date(element.operation_meeting_date).getDate()
    //     // } else {
    //     //   element.operation_meeting_date = ""
    //     // }
    //     // if (element.board_meeting_date != null) {
    //     //   element.board_meeting_date = new Date(element.board_meeting_date).getFullYear() + '-' + (new Date(element.board_meeting_date).getMonth() + 1) + '-' + new Date(element.board_meeting_date).getDate()
    //     // } else {
    //     //   element.board_meeting_date = ""
    //     // }
    //     // if (element.expire_date != null) {
    //     //   element.expire_date = new Date(element.expire_date).getFullYear() + '-' + (new Date(element.expire_date).getMonth() + 1) + '-' + new Date(element.expire_date).getDate()
    //     // } else {
    //     //   element.expire_date = ""
    //     // }
    //     // if (element.create_date != null) {
    //     //   element.create_date = new Date(element.create_date).getFullYear() + '-' + (new Date(element.create_date).getMonth() + 1) + '-' + new Date(element.create_date).getDate()
    //     // } else {
    //     //   element.create_date = ""
    //     // }
    //     // if (element.modify_date != null) {
    //     //   element.modify_date = new Date(element.modify_date).getFullYear() + '-' + (new Date(element.modify_date).getMonth() + 1) + '-' + new Date(element.modify_date).getDate()
    //     // } else {
    //     //   element.modify_date = ""
    //     // }
    //   });

    //   setTimeout(() => {
    //     this.setState({
    //       loading: false,
    //       inSearchOf: false,
    //       data: screenList,
    //       totalnum: screenList.length,
    //       exportData:{
    //         ...this.state.exportData,
    //         data: screenList
    //       }
    //     })
    //     
    //   }, 500)
    // }
  }


  // 切换分页
  public async ontab(e) {

    this.setState({
      loading: true
    })

    // let obj = JSON.parse(JSON.stringify(this.state.data));

    const obj = [...this.state.data];

    let size = e * 10 - 10
    // 追加附件的数据数量
    let num = 10
    let arr = []
    for (let i = 0; i < num; i++) {
      arr.push(obj[size])
      size++
    }

    arr.forEach(async element => {
      if (element.file != undefined) {
        return
      }
      if (element.SRUrls != null) {
        let index = element.SRUrls.lastIndexOf("/")
        element.SRUrls = element.SRUrls.substring(0, index);
        let file = await Api.getFiles(element.SRUrls);
        // 处理时间排序
        // file.sort(function (a, b) {
        //   return b.TimeCreated < a.TimeCreated ? -1 : 1
        // })
        element.file = file
      } else {
        let file = []
        element.file = file
      }
    });

    setTimeout(() => {
      this.setState({
        loading: false,
        // data: obj
        data: [...obj]
      })
    }, 2000)

  }

}
export default Form.create()(SearchApplyRegulationsFile);
